package com.guessnumber.listener;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import com.guessnumber.guess.chestinterface.myinventoryholder;
import com.guessnumber.guess.chestinterface.myinv;

public class listener implements Listener {
    @EventHandler
    public void whenclick(InventoryClickEvent ice){
        if (ice.getClickedInventory() == null) return;
        if (ice.getClickedInventory().getHolder(false) == null) return;
        if (ice.getClickedInventory().getHolder(false) instanceof myinventoryholder){
            myinventoryholder holder = (myinventoryholder)ice.getClickedInventory().getHolder(false);
            if (holder.passw.equals("SHOWING")){
                ice.setCancelled(true);
            }
        }
        else if (ice.getClickedInventory().getHolder(false) instanceof myinv.myinvholder){
            myinv.myinvholder holder = (myinv.myinvholder)ice.getClickedInventory().getHolder(false);
            int[] imap = holder.indexmap;
            if (holder.passw.equals("HWFG'S INVENTORY")){
                for (int i = 0;i < imap.length;i++){
                    if (imap[ice.getSlot()] != -1){ //indexmap[槽位] => 物品序号
                        myinv.widget w = holder.generalwid.get(imap[ice.getSlot()]);
                        ice = w.WhenClick(ice);
                        return;
                    }
                }
            }
        }
    }
}
